<template>
  <a-config-provider :locale="locale">
    <div id="app">
      <router-view />
    </div>
  </a-config-provider>
</template>
<script>
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
import enquireScreen from '@/utils/device'

export default {
  data() {
    return {
      locale: zhCN
    }
  },
  created() {
    let that = this
    enquireScreen(deviceType => {
      // tablet
      if (deviceType === 0) {
        that.$store.commit('TOGGLE_DEVICE', 'mobile')
        that.$store.dispatch('setSidebar', false)
      }
      // mobile
      else if (deviceType === 1) {
        that.$store.commit('TOGGLE_DEVICE', 'mobile')
        that.$store.dispatch('setSidebar', false)
      } else {
        that.$store.commit('TOGGLE_DEVICE', 'desktop')
        that.$store.dispatch('setSidebar', true)
      }
    })
  },
  mounted() {
    // 用户打开项目即开始
    const p = this.$store.dispatch('alarm/startGlobalTimer')
    console.log('dispatch 返回', p) // 应该是 Promise
    p.then(res => console.log('成功', res)).catch(e => console.error('失败', e))
    this.$store.dispatch('alarm/getActiveInfo')
  },
  beforeDestroy() {
    // 整个应用关闭时停止（可选）
    this.$store.dispatch('alarm/stopGlobalTimer')
  }
}
</script>
<style>
#app {
  height: 100%;
}
</style>
